package model

// Mail 邮件的表结构体
type Mail struct {
	ID      int64  `db:"id" json:"id"`           //  id
	Mail    string `db:"mail" json:"mail"`       //  接收地址
	Title   string `db:"title" json:"title"`     //  邮件标题
	Data    string `db:"data" json:"data"`       //  发送内容
	Created int64  `db:"created" json:"created"` //  发送时间戳
}

// SedMail 发送邮件到其他人
/*func SedMail(mailTo string, subject string, body string) (int, error) {
	m := gomail.NewMessage()
	m.SetHeader("From", config.MailUser)
	//m.SetHeader("To", mailTo...)    //发送给多个用户
	m.SetHeader("To", mailTo)       //发送给单个用户
	m.SetHeader("Subject", subject) //设置邮件主题
	m.SetBody("text/html", body)    //设置邮件正文
	//加载配置文件的mail的qq配置
	d := gomail.NewDialer(config.MailHost, config.MailPort, config.MailUser, config.MailPass)
	//发送邮件，会自动关闭连接
	err := d.DialAndSend(m)
	if err != nil {
		log.Error("mail发送错误，检查", err)
		return 201, err
	}
	insmail(mailTo, subject, body, time.Now().Unix()) //写入发送记录
	log.Info("mail发送成功")
	return 200, err

}*/

/*//  写入发送记录
func insmail(mail, title, data string, created int64) {
	sqlStr := "insert into mail(mail, title,data,created) values (?,?,?,?)"
	ret, err := mysql.Db.Exec(sqlStr, mail, title, data, created)
	if err != nil {
		log.Info("insert failed, err:%v\n", err)
		return
	}
	theID, err := ret.LastInsertId() // 新插入数据的id
	if err != nil {
		log.Error("插入出错", err)
		return
	}
	log.Info("mail插入成功，id：", theID)
}

// GetMail 查看mail历史记录
func GetMail(n, m int) (code int, a []Mail) {
	sqlStr := "select *  from mail  order by id DESC LIMIT ?,?"
	err := mysql.Db.Select(&a, sqlStr, (n-1)*m, m)
	if err != nil {
		log.Error("查询分页文章报错", err)
		return 201, a
	}
	return 200, a
}*/
